// 推荐模块API封装

import api from '../index';
import { ApiResponse } from '../../types';
import {
  RecommendationContent,
  ContentFeatureStatistics,
  RetryFailedTasksResponse,
  CleanupTimeoutTasksResponse,
  CleanupTimeoutParams
} from '../../types/recommendation/recommendation';

/**
 * 推荐相关API
 */
export const recommendationApi = {
  /**
   * 获取下一个推荐内容
   * @returns Promise<ApiResponse<RecommendationContent>>
   */
  getNextRecommendation: async (): Promise<ApiResponse<RecommendationContent>> => {
    const response = await api.get<ApiResponse<RecommendationContent>>('/recommendations/next');
    return response.data;
  }
};

/**
 * 内容特征管理API（管理员功能）
 */
export const contentFeatureAdminApi = {
  /**
   * 获取内容特征任务统计
   * @returns Promise<ApiResponse<ContentFeatureStatistics>>
   */
  getStatistics: async (): Promise<ApiResponse<ContentFeatureStatistics>> => {
    const response = await api.get<ApiResponse<ContentFeatureStatistics>>('/content-feature/admin/statistics');
    return response.data;
  },

  /**
   * 重试所有失败任务
   * @returns Promise<ApiResponse<RetryFailedTasksResponse>>
   */
  retryFailedTasks: async (): Promise<ApiResponse<RetryFailedTasksResponse>> => {
    const response = await api.post<ApiResponse<RetryFailedTasksResponse>>('/content-feature/admin/retry-failed');
    return response.data;
  },

  /**
   * 清理超时任务
   * @param params 清理参数，可选超时时间
   * @returns Promise<ApiResponse<CleanupTimeoutTasksResponse>>
   */
  cleanupTimeoutTasks: async (params?: CleanupTimeoutParams): Promise<ApiResponse<CleanupTimeoutTasksResponse>> => {
    const response = await api.post<ApiResponse<CleanupTimeoutTasksResponse>>(
      '/content-feature/admin/cleanup-timeout',
      null,
      { params }
    );
    return response.data;
  }
};

// 导出所有API
export const {
  getNextRecommendation
} = recommendationApi;

export const {
  getStatistics,
  retryFailedTasks,
  cleanupTimeoutTasks
} = contentFeatureAdminApi; 